package converters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

import repositories.PagoRepository;
import domain.Pago;

public class StringToPagoConverter implements Converter<String, Pago> {

	@Autowired
	PagoRepository pagoRepository;

	@Override
	public Pago convert(String text) {
		Pago result;
		int id;

		try {
			id = Integer.valueOf(text);
			result = pagoRepository.findOne(id);
		} catch (Throwable oops) {
			throw new IllegalArgumentException(oops);
		}

		return result;
	}
}
